package rabbitmq.topic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import rabbitmq.utils.MqUtil;

import java.io.IOException;

public class Consumer02 {

    private final static String TOPIC_MSG="TOPIC_MSG";

    public static void main(String[] args) throws IOException {
        MqUtil mqUtil=new MqUtil();
        Channel channel = mqUtil.getChananel();
        channel.exchangeDeclare(TOPIC_MSG, BuiltinExchangeType.TOPIC);
        String queueName = "Q2";
        channel.queueDeclare(queueName,false,false,false,null);
        channel.queueBind(queueName,TOPIC_MSG,"*.*.rabbit");
        channel.queueBind(queueName,TOPIC_MSG,"lazy.#");
        DeliverCallback deliverCallback = (consumerTag,deliver)->{
            String msg = new String(deliver.getBody());
            System.out.println("消费者02消费了"+msg);
        };
        channel.basicConsume(queueName,true,deliverCallback,consumerTag->{});
    }
}
